package com.ifelse.better.handler;

import com.ifelse.better.TopicEnum;
import com.ifelse.better.handler.impl.ComputerHandler;
import com.ifelse.better.handler.impl.PadHandler;
import com.ifelse.better.handler.impl.PhoneHandler;

/**
 * desc:
 *
 * @author gaorimao
 * @since 2023-11-16-14:56
 */
public class ConsumerHandlerFactory {
    public static ConsumerHandler createHandler(String topic) {
        System.out.println("走的是if else生产Handler");
        if (topic.equals(TopicEnum.PHONE.getTopic())) {
            return new PhoneHandler();
        } else if (topic.equals(TopicEnum.COMPUTER.getTopic())) {
            return new ComputerHandler();
        } else if (topic.equals(TopicEnum.PAD.getTopic())) {
            return new PadHandler();
        } else {
            throw new IllegalArgumentException("Invalid topic!");
        }
    }


//    public static ConsumerHandler createHandlerV2(TopicEnum topic) {
//        System.out.println("走的是switch case生产Handler");
//        return switch (topic) {
//            case PHONE -> new PhoneHandler();
//            case COMPUTER -> new ComputerHandler();
//            case PAD -> new PadHandler();
//        };
//    }
}